﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class admin_commentlist : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Session["login"] == null)
            {
                Response.Redirect("login.aspx");
            }
            else
            {
                rptdatabind();
            }
        } 
    }
    protected void rptcommentlist_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        YqhData obj = new YqhData();
        switch (e.CommandName.ToLower())
        {
            case "del":
                string sql = string.Format("delete comment where cid={0}", e.CommandArgument);
                obj.ExecuteSql(sql);
                rptdatabind();
                break;
            case "pb":
                string nr = "<span style=color:#ff0000>*该评论被管理员屏蔽*</span>";
                string sql2 = string.Format(@"update comment set ccontent='{0}' 
where cid={1}",nr,e.CommandArgument);
                obj.ExecuteSql(sql2);
                rptdatabind();
                break;
        }
    }

    private void rptdatabind()
    {
        YqhData obj = new YqhData();
        AspNetPager1.RecordCount = Convert.ToInt32(obj.ExecuteScalar("select count(*) from comment"));
        int pageindex = AspNetPager1.CurrentPageIndex - 1;
        int pagesize = AspNetPager1.PageSize;
        string sql = @"select cid,cname,nsubject,ccontent,cdate
from comment inner join news on nid=cnewsid order by cdate desc";
        rptcommentlist.DataSource = obj.ExecuteDataSet(sql, pageindex, pagesize);
        rptcommentlist.DataBind();
    }
    protected void AspNetPager1_PageChanged(object sender, EventArgs e)
    {
        rptdatabind();
    }
}
